//
//  UITableView+EmptyData.m
//  yilutongxing
//
//  Created by T&J on 2017/6/19.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "UITableView+EmptyData.h"
#import "UIImage+QMUI.h"

@implementation UITableView (EmptyData)

-(void)tableViewDisplayWithPicAndMsg:(NSString *)message ifNecessaryForRowCount:(NSUInteger)rowCount{
    if (rowCount==0) {
        UIImage *emptyimg = [UIImage imageNamed:@"暂无内容"];
        UIImageView *emptyview = [[UIImageView alloc]initWithImage:emptyimg];
        emptyview.origin = CGPointMake((self.width-emptyimg.size.width)/2, (self.height-emptyimg.size.height-30)/2);
        emptyview.size = emptyimg.size;
        UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        bg.backgroundColor = COLOR(190, 190, 190);
        UILabel *msglabel = [[UILabel alloc]initWithFrame:CGRectMake(emptyview.x, emptyview.y+emptyview.height, emptyview.width, 30)];
        msglabel.textColor = COLOR(166, 166, 166);
        msglabel.textAlignment = NSTextAlignmentCenter;
        msglabel.text = message;
        [bg addSubview:msglabel];
        [bg addSubview:emptyview];
        self.backgroundView = bg;
    }
    else
        self.backgroundView = nil;
}

-(void)tableViewDisplayWithMsg:(NSString *)message ifNecessaryForRowCount:(NSUInteger)rowCount{
    if (rowCount==0) {
        UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        bg.backgroundColor = COLOR(190, 190, 190);
        UILabel *msglabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (bg.height-30)/2, bg.width, 30)];
        msglabel.textColor = COLOR(166, 166, 166);
        msglabel.textAlignment = NSTextAlignmentCenter;
        msglabel.text = message;
        [bg addSubview:msglabel];
        self.backgroundView = bg;
    }
    else
        self.backgroundView = nil;
}

-(void)tableViewDisplayMsgWithClearBg:(NSString *)message msgcolor:(UIColor *)color ifNecessaryForRowCount:(NSUInteger)rowCount{
    if (rowCount==0) {
        UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        bg.backgroundColor = [UIColor clearColor];
        UILabel *msglabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (bg.height-30)/2, bg.width, 30)];
        msglabel.textColor = color;
        msglabel.textAlignment = NSTextAlignmentCenter;
        msglabel.text = message;
        [bg addSubview:msglabel];
        self.backgroundView = bg;
    }
    else
        self.backgroundView = nil;
}

@end
